package Day9;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class CalDemo {

	public static void main(String[] args) {
		//创建JFrame
		JFrame frame = new JFrame("FlowLayoutDemo");
		Panel panel = new Panel();
		frame.add(panel);
		
		//设置布局
		panel.setLayout(new FlowLayout(FlowLayout.LEFT));
		
		//文本框1
		JTextField testField = new JTextField();
		testField.setPreferredSize(new Dimension(120,30));
		panel.add(testField);
		
		//*号
		JLabel label = new JLabel("*");
		label.setPreferredSize(new Dimension(30,30));
		panel.add(label);
		
		//文本框2
		JTextField textField2 = new JTextField();
		textField2.setPreferredSize(new Dimension(120,30));
		panel.add(textField2);
		
		//=号
		JButton button = new JButton("=");
		panel.add(button);
		
		JLabel resultLabel = new JLabel();
		panel.add(resultLabel);
		
		//给button添加点击事件
		button.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				String num1 = testField.getText();
				System.out.println(num1);
				String num2 = textField2.getText();
				System.out.println(num2);
				long result = Long.parseLong(num1) * Long.parseLong(num2);
				resultLabel.setText(Long.toString(result));
			}
		});
		
		//设置JFrame属性，大小，可见，尺寸
		frame.setResizable(false);
		frame.setSize(500,300);
		frame.setVisible(true);
		frame.setLocation(500, 400);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

}
